import { loadLocaleMessages } from '@/locales';

import { SupportLanguage } from '@/types/enums';

export const useLocale = () => {
  const { locale, messages } = useI18n();
  const changeLocale = async (lang: SupportLanguage) => {
    loadLocaleMessages(lang).then(() => {
      locale.value = lang;
    });
  };

  const getElementPlusLocale = reactify((messages: any, locale: any) => {
    return messages[locale]['elementplus'];
  });

  return {
    changeLocale,
    elementplus: getElementPlusLocale(messages, locale),
  };
};
